package com.zsq.common.base;

/**
 * [400,500) 客户端错误
 * [500,600) 服务端错误
 * @author zsq
 * @date 2019/11/21 - 17:34
 */
public class BaseResult<T> {

    public static int SUCCESS = 200;
    public static int FAIL = -1;

    public static int FAIL_CLIENT = 400;
    public static int FAIL_SERVER = 500;


    private int status;
    private String message;
    private String errorMessage;
    private T data;

    public static BaseResult ok(){
        BaseResult<Object> result = new BaseResult<>();
        result.setStatus(SUCCESS);
        return result;
    }

    public static BaseResult ok(String message){
        BaseResult<Object> result = new BaseResult<>();
        result.setStatus(SUCCESS);
        result.setMessage(message);
        return result;
    }

    public static BaseResult fail(){
        BaseResult<Object> result = new BaseResult<>();
        result.setStatus(FAIL);
        return result;
    }
    public static BaseResult fail(String errorMessage){
        BaseResult<Object> result = new BaseResult<>();
        result.setStatus(FAIL);
        result.setErrorMessage(errorMessage);
        return result;
    }

    public static BaseResult failClient(){
        BaseResult<Object> result = new BaseResult<>();
        result.setStatus(FAIL_CLIENT);
        return result;
    }

    public static BaseResult failServer(){
        BaseResult<Object> result = new BaseResult<>();
        result.setStatus(FAIL_SERVER);
        return result;
    }

    public BaseResult() {
    }

    @Override
    public String toString() {
        return "BaseResult{" +
                "status=" + status +
                ", message='" + message + '\'' +
                ", errorMessage='" + errorMessage + '\'' +
                ", data=" + data +
                '}';
    }

    public int getStatus() {
        return status;
    }

    public void setStatus(int status) {
        this.status = status;
    }

    public String getMessage() {
        return message;
    }

    public BaseResult<T> setMessage(String message) {
        this.message = message;
        return this;
    }

    public String getErrorMessage() {
        return errorMessage;
    }

    public BaseResult<T> setErrorMessage(String errorMessage) {
        this.errorMessage = errorMessage;
        return this;
    }

    public T getData() {
        return data;
    }

    public BaseResult<T> setData(T data) {
        this.data = data;
        return this;
    }
}
